﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ACLMedicos
{
    public partial class Search : Form
    {
        // lol
        SqlConnection connection = new SqlConnection("Data Source= localhost; Database=ACLMedicos; Integrated Security=SSPI");
        DataSet dsorder = new DataSet();
        SqlDataAdapter daorder = new SqlDataAdapter();
        SqlCommand commnad;
        public Search()
        {
            InitializeComponent();
        }

        private void Search_Load(object sender, EventArgs e)
        {
            connection.Open();
            String commandText = "select * from OrderDetails";
            daorder = new SqlDataAdapter(commandText, connection);
            daorder.Fill(dsorder, "OrderDetails");
            dgv_Order.DataSource = dsorder;
            dgv_Order.DataMember = "OrderDetails";
            AddItemOnComboBox();
        }
        void AddItemOnComboBox()
        {
            cbb_sort.Items.Clear();
            for (int i = 0; i < dsorder.Tables["OrderDetails"].Columns.Count; i++)
            {
                cbb_sort.Items.Add(dsorder.Tables["OrderDetails"].Columns[i].ToString());
            }
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            dsorder.Clear();
            string commandText = "Select * From OrderDetails where CustomerID LIKE '" + txt_search.Text + "%'";
            daorder = new SqlDataAdapter(commandText, connection);
            daorder.Fill(dsorder, "OrderDetails");
            
        }

        private void cbb_sort_SelectedIndexChanged(object sender, EventArgs e)
        {
            dgv_Order.Sort(dgv_Order.Columns[`, ListSortDirection.Ascending);
        }
    }
}
